﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NETL.Engine.Context;
using NETL.Engine.Util;
using System.Xml.Linq;

namespace NETL.Engine.Destination
{
	public class DestinationFactory : IDestinationFactory
	{
		public static IDestinationFactory Instance()
		{
			return new DestinationFactory();
		}

		#region IDestinationFactory Members

		public IMessageDestination BuildDestination(NETL.Data.Config.DestinationData data)
		{
			IMessageDestination d = ClassFactory.Instance().BuildClass(data.Class) as IMessageDestination;
			d.Name = data.Name;

			foreach (XElement e in data.Data.Elements())
			{
				ReflectionUtil.SetProperty(d, e);
			}

			return d;
		}

		#endregion
	}
}
